package com.djz.tool.controller;

import com.djz.tool.exception.category.BusinessException;
import com.djz.tool.service.VideoService;
import com.djz.tool.utils.ResponseUtils;
import com.djz.tool.wrapper.ResponseWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/api/video")
public class VideoController {

    @Autowired
    private VideoService videoService;

    @PostMapping("/upload")
    public ResponseEntity<ResponseWrapper<Map<String, Object>>> uploadVideo(@RequestParam("file") MultipartFile file) {
        String filePath = videoService.saveUploadedFile(file);
        Map<String, Object> map = new HashMap<>(2);
        map.put("path", filePath);
        return ResponseUtils.success(map).toResponseEntity(HttpStatus.OK);
    }

    @GetMapping("/list")
    public ResponseEntity<ResponseWrapper<String>> cutVideo() {
        int i = 0;
        if (i == 0) {
            throw  new BusinessException(1,"1");
        }
        return ResponseUtils.success("剪辑成功").toResponseEntity(HttpStatus.OK);
    }
}
